package com.easy;

import java.util.HashSet;
import java.util.Set;

/**
 * Created by Lxk on 2019/8/11.
 */
public class Solution929 {

    public int numUniqueEmails(String[] emails) {
        int res = 0;
        if (emails == null || emails.length == 0) {
            return res;
        }
        Set<String> trueEmailAddr = new HashSet<>();
        for (String val : emails) {
            trueEmailAddr.add(handleEmailAddr(val));
        }
        return trueEmailAddr.size();
    }

    private String handleEmailAddr(String val) {
        String[] splitLD = val.split("@");
        String localName = splitLD[0].replace(".", "").split("\\+")[0];
        String domainName = splitLD[1];
        return localName + "@" + domainName;
    }

    public static void main(String[] args) {
        Solution929 solution929 = new Solution929();
        String[] data = {"test.email+alex@leetcode.com", "test.e.mail+bob.cathy@leetcode.com", "testemail+david@lee.tcode.com"};
        int count = solution929.numUniqueEmails(data);
        System.out.println(count);

    }

}
